home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 19 / Amiga Plus Leser CD 19.iso / Tools / Freeware / Swf_Player / Player / audio.c next >
Encoding:
C/C++ Source or Header  |  2002-11-17  |  3.0 KB  |  142 lines

  1. /*
  2. **
  3. ** $VER: audio.c 0.1 (04.03.99)
  4. ** Description
  5. **
  6. ** (C) Copyright 1999 Paul Hill
  7. **
  8. */
  9.  
  10. #include <stdio.h>
  11. #ifdef __PPC__
  12. #include </ADE/os-includeppc/proto/exec.h>
  13. #else
  14. #include <proto/exec.h>
  15. #endif
  16. #include <devices/audio.h>
  17. #include <graphics/gfxbase.h>
  18.  
  19. #include "swfplayer.h"
  20.  
  21. static struct MsgPort *AudioPort = NULL;
  22. static struct IOAudio *AudioMsg = NULL;
  23. static UBYTE DeviceOpen = FALSE;
  24.  
  25. extern struct GfxBase *GfxBase;
  26. static ULONG clock_constant;
  27.  
  28. BOOL audio_init()
  29. {
  30. #ifdef SOUND
  31.     UBYTE MyChannels [] = {15};
  32.  
  33.     AudioPort = CreateMsgPort ();
  34.     if (!AudioPort) return FALSE;
  35.  
  36.     AudioMsg = CreateIORequest (AudioPort, sizeof (struct IOAudio));
  37.     if (!AudioMsg) return FALSE;
  38.  
  39.     AudioMsg->ioa_Request.io_Message.mn_ReplyPort = AudioPort;
  40.     AudioMsg->ioa_Request.io_Message.mn_Node.ln_Pri = 127;
  41.     AudioMsg->ioa_Request.io_Command = ADCMD_ALLOCATE;
  42.     AudioMsg->ioa_Request.io_Flags = ADIOF_NOWAIT;
  43.     AudioMsg->ioa_AllocKey = 0;
  44.     AudioMsg->ioa_Data = MyChannels;
  45.     AudioMsg->ioa_Length = 1;
  46.  
  47.     // Open audio device
  48.  
  49.     DeviceOpen = !OpenDevice ("audio.device", 0, (struct IORequest *)AudioMsg, 0);
  50.     if (!DeviceOpen) return FALSE;
  51.  
  52. //    ML_InitSCC ();
  53.  
  54.     TRACE("audio initialised\n");
  55.  
  56.     if ((GfxBase->DisplayFlags & NTSC) != 0)
  57.         clock_constant = 3579545;   // NTSC
  58.     else
  59.         clock_constant = 3546895;   // PAL
  60.  
  61.  
  62. //  if ((c->chip_data = AllocMem (lengths[id], MEMF_CHIP)) == NULL)
  63. #endif
  64.     return TRUE;
  65. }
  66.  
  67.  
  68.  
  69.  
  70. void audio_trash()
  71. {
  72. #ifdef SOUND
  73.     if (DeviceOpen)
  74.     {
  75. //        ML_ExitSCC ();
  76.         CloseDevice ((struct IORequest *)AudioMsg);
  77.         DeviceOpen = FALSE;
  78.     }
  79.  
  80.     if (AudioMsg)
  81.     {
  82.         DeleteIORequest (AudioMsg);
  83.         AudioMsg = NULL;
  84.     }
  85.  
  86.     if (AudioPort)
  87.     {
  88.         DeleteMsgPort (AudioPort);
  89.         AudioPort = NULL;
  90.     }
  91.  
  92.     TRACE("audio closed\n");
  93. #endif
  94. }
  95.  
  96.  
  97.  
  98. /**********************************************************************/
  99. // Starts a sound in a particular sound channel.
  100. int I_StartSound (
  101.   int id,
  102.   int cnum,
  103.   int vol,
  104.   int sep,
  105.   int pitch,
  106.   int priority )
  107. {
  108. #ifdef SOUND
  109.   struct channel_info *c;
  110.  
  111.   /* fprintf (stderr, "I_StartSound(%d,%d,%d,%d,%d,%d)\n", id, cnum, vol, sep,
  112.               pitch, priority); */
  113.   I_StopSound (cnum);
  114.   c = &channel_info[cnum];
  115.   c->audio_io->ioa_Request.io_Command = CMD_WRITE;
  116.   c->audio_io->ioa_Request.io_Flags = ADIOF_PERVOL;
  117.   c->audio_io->ioa_Data = &chip_cache_info[cache_chip_data (id)].chip_data[8];
  118.   c->audio_io->ioa_Length = lengths[id] - 8;
  119.   c->audio_io->ioa_Period = period_table[pitch];
  120.   c->audio_io->ioa_Volume = vol << 3;
  121.   c->audio_io->ioa_Cycles = 1;
  122.   BeginIO ((struct IORequest *)c->audio_io);
  123.   c->sound_in_progress = TRUE;
  124. #endif
  125.   return cnum;
  126. }
  127.  
  128. /**********************************************************************/
  129. // Stops a sound channel.
  130. void I_StopSound(int handle)
  131. {
  132. #ifdef SOUND
  133.   /* fprintf (stderr, "I_StopSound(%d)\n", handle); */
  134.   if (channel_info[handle].sound_in_progress) {
  135.     AbortIO ((struct IORequest *)channel_info[handle].audio_io);
  136.     WaitPort (channel_info[handle].audio_mp);
  137.     GetMsg (channel_info[handle].audio_mp);
  138.     channel_info[handle].sound_in_progress = FALSE;
  139.   }
  140. #endif
  141. }
  142.